const itemNames = `bolt-bomb.png, chicken-oven.png, cluster-bomb.png, fire-bomb.png, ice-bomb.png, key.png, locked-chest.png, magic-lamp.png, meat.png, paper-crane.png, potion-ball.png, round-bottom-flask.png, rupee.png, super-mushroom.png, treasure-map.png, unlit-bomb.png, wanted-reward`.replace(/, ?/g, "").split('.png');
// 17种物品
const itemTips = [
    ["电光炸弹", "暴击率加成"],
    ["烤鸡", "立即恢复大量hp"],
    ["连锁炸弹", "命中加成"],
    ["火焰炸弹", "攻击加成"],
    ["冰霜炸弹", "防御加成"],
    ["钥匙", "打开宝箱"],
    ["上锁宝箱", "需要钥匙打开，打开后获得物品"],
    ["神灯", "许愿获得加成或物品或传送到下一层"],
    ["小肉块", "立即恢复中量hp"],
    ["纸鹤", "速度加成"],
    ["小蓝瓶", "战时恢复蓝"],
    ["小血瓶", "战时恢复血"],
    ["能量水晶", "战时后四项属性加成"],
    ["迷幻蘑菇", "战斗前随机获得buff或debuff"],
    ["藏宝图", "到达指定地点，获得物品奖励"],
    ["投掷炸弹", "幸运加成"],
    ["悬赏令", "击杀特定的怪物，获得加成或物品奖励"],
]
// 战斗前加成一次 a
// 加入事件队列达到特定条件时触发 once eventQueue
// 战斗前赋予buff buff
// 战斗中持续产生特殊效果 func
const itemData = [
    {
        a: [0, 0, 0, 0, 0, 0, 0, 30]
    },
    {
        get: () => {
            game.hero.heroInfo.hp += Math.round(game.hero.heroInfo.abilities[0] * 0.65);
            if (game.hero.heroInfo.hp > game.hero.heroInfo.abilities[0]) {
                game.hero.heroInfo.hp = game.hero.heroInfo.abilities[0]
            }
        }
    },
    {
        a: [0, 0, 0, 0, 30, 0, 0, 0]
    },
    {
        a: [0, 0, 30, 0, 0, 0, 0, 0]
    },
    {
        a: [0, 0, 0, 30, 0, 0, 0, 0]
    },
    {
        once: () => {
            console.log("钥匙可以打开宝箱");
            if (game.hero.itemId.indexOf(6) > -1) {
                game.hero.itemId.splice(game.hero.itemId.indexOf(6), 1);
                game.hero.itemId.splice(game.hero.itemId.indexOf(5), 1);
                game.hero.getItem(getRandomItem());
                return true;
            } else {
                return false;
            }
        }
    },
    {
        once: () => {
            console.log("需要钥匙才能开箱");
            game.hero.getExp(10);
            return true;
        }
    },
    {
        get: () => {
            console.log("向神灯许愿");
            if (game.hero.petInfo.readyPet.length < 1) {
                game.hero.getPet(0)
                console.log("神灯赐予你宠物");
            } else {
                game.hero.getItem(getRandomItem());
                console.log("神灯赐予你宝物");
            }
        }
    },
    {
        get: () => {
            game.hero.heroInfo.hp += Math.round(game.hero.heroInfo.abilities[0] * 0.35);
            if (game.hero.heroInfo.hp > game.hero.heroInfo.abilities[0]) {
                game.hero.heroInfo.hp = game.hero.heroInfo.abilities[0]
            }
        }
    },
    {
        a: [0, 0, 0, 0, 0, 0, 30, 0]
    },
    {
        func: (stat) => {
            if (stat[1] < game.hero.heroInfo.abilities[1]) {
                stat[1] += 1;
            }
        }
    },
    {
        func: (stat) => {
            if (stat[0] < game.hero.heroInfo.abilities[0]) {
                stat[0] += 2;
                if (stat[0] > game.hero.heroInfo.abilities[0]) {
                    stat[0] = game.hero.heroInfo.abilities[0]
                }
            }
        }
    },
    {
        func: (stat) => {
            for (let i = 4; i < stat.length; i++) {
                stat[i] += 1;
            }
        }
    },
    {
        buff: () => {
            let _rate = Math.random()
            if (_rate > 0.7) {
                // buff
                heroBuff.push({ id: getRandomRange(0, 20), type: 0, turn: 1 })
            }
            if (_rate < 0.3) {
                // debuff
                heroBuff.push({ id: getRandomRange(0, 23), type: 1, turn: 1 })
            }
        }
    },
    {
        get: () => {
            let _p = getRandomRange(0, 20)
            game.hero.itemInfo.treasureHouse.push(_p);
            console.log("藏宝地点：", areaTips[_p][0]);
        },
        once: () => {
            console.log(itemTips[14][0], itemTips[14][1]);
            let _i = game.hero.itemInfo.treasureHouse.indexOf(game.cur_hero_pos)
            if (_i > -1) {
                game.hero.itemInfo.treasureHouse.splice(_i, 1)
                game.hero.getItem(getRandomItem())
                return true;
            } else {
                return false;
            }
        }
    },
    {
        a: [0, 0, 0, 0, 0, 30, 0, 0]
    },
    {
        get: () => {
            let _p = getRandomPet()
            game.hero.itemInfo.monsterReward.push(_p);
            console.log("悬赏怪物：", monsterTips[_p][0]);
        },
        once: (id) => {
            console.log(itemTips[16][0], itemTips[16][1]);
            let _i = game.hero.itemInfo.monsterReward.indexOf(id)
            if (_i > -1) {
                game.hero.itemInfo.monsterReward.splice(_i, 1)
                game.hero.getItem(getRandomItem());
                return true;
            } else {
                return false;
            }
        }
    }
]